import threading
smp=0;tmp=0
def thread_entry():
    global smp,tmp
    for i in range(1000**2):
        lock.acquire()
        tmp=smp+1
        smp=tmp
        lock.release()
lock=threading.Lock()
t0=threading.Thread(target=thread_entry,args=())
t1=threading.Thread(target=thread_entry,args=())
t0.start();t1.start();t0.join();t1.join()
print('sum =',smp)
